package com.ruoyi.equipment.service.impl;

import com.ruoyi.equipment.domain.LgColdStorage;
import com.ruoyi.equipment.domain.LgMachine;
import com.ruoyi.equipment.domain.LgSubCold;
import com.ruoyi.equipment.mapper.LgMachineMapper;
import com.ruoyi.equipment.service.LgMachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: lek
 * @Description: TODO
 * @Date: 2025/3/10 9:06
 * @Version: 1.0
 */
@Service
public class LgMachineServiceImpl implements LgMachineService {
    @Autowired
    private LgMachineMapper lgMachineMapper;
    /**
     * @author maisan
     * @description 查找所有冷库机信息
     * @createTime  2025/3/7 14:52
     * @param [com.ruoyi.equipment.domain.LgMachine]
     * @return java.util.List<com.ruoyi.equipment.domain.LgMachine>
     **/

    public List<LgMachine> selectLgMachineList(LgMachine lgMachine){
        return lgMachineMapper.selectLgMachineList(lgMachine);
    }
    /**
     * @author maisan
     * @description 新增冷库机信息
     * @createTime  2025/3/7 14:52
     * @param [com.ruoyi.equipment.domain.LgMachine]
     * @return java.util.List<com.ruoyi.equipment.domain.LgMachine>
     **/
    public int insertLgMachine(LgMachine lgMachine){
        return lgMachineMapper.insert(lgMachine);
    }
    /**
     * @author maisan
     * @description //TODO 根据id查找冷库机信息
     * @createTime  2025/3/7 18:41
     * @param
     * @return
     **/
    public LgMachine selectLgMachineById(Integer id){
        return lgMachineMapper.selectLgMachineById(id);
    }

    /**
     * @author maisan
     * @description 修改冷库机信息
     * @createTime  2025/3/7 18:39
     * @param
     * @return
     **/
    public int updateLgMachine(LgMachine lgMachine){
        return lgMachineMapper.updateById(lgMachine);
    }
    /**
     * @author maisan
     * @description 删除
     * @createTime  2025/3/7 18:39
     * @param
     * @return
     **/
    public int deleteLgMachineById(Integer[] ids){
        for (int i = 0; i < ids.length; i++){
            LgMachine lgMachine = lgMachineMapper.selectLgMachineById(ids[i]);
            lgMachine.setId(ids[i]);
            lgMachine.setColdStorageId(0);
            //删除时解车辆
            lgMachineMapper.updateById(lgMachine);
        }
        return lgMachineMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * @author maisan
     * @description 获取绑定的冷酷信息
     * @createTime  2025/3/8 11:00
     * @param
     * @return
     **/
    public LgSubCold selectSubColdById(Integer id){
        return lgMachineMapper.selectSubColdById(id);
    }
}
